﻿function reader_bg(colr) {
    document.body.style.background = colr;
}
function font_color(color) {
    document.getElementById('reader-bg').style.color = color;
}
function font_size(size,height) {
    document.getElementById('reader-bg').style.fontSize = size;
    document.getElementById('reader-bg').style.lineHeight = height;

}
/**
双击滚屏
*/
var currentpos, timer;
function initialize() {
    timer = setInterval("scrollwindow()", 50);
}


window.bookInfo = {
    bookId: '',
    bookName: '',
    bookDownUrl: '',
    chapterId: '',
    chapterName:''
};

$(document).ready(function () {
    $('a.book-down').bind('click', function (e) {
        e.preventDefault();
        bookInfo.bookId = this.getAttribute('data-book-id');
        bookInfo.bookName = this.getAttribute('data-book-name');
        bookInfo.bookDownUrl = this.getAttribute('data-book-downurl');
        bookInfo.chapterId = this.getAttribute('data-chapter-id');
        bookInfo.chapterName = this.getAttribute('data-chapter-name');
        show_book_down(bookInfo);
    });
    $('#login').bind('click', function (e) {
        e.preventDefault();
      $.Zebra_Dialog( {
            source: { 'ajax': 'http://localhost:14952/home/login.html?resulr='+window.location.href  },
            width: 400,
            title: false, 'type': false,
            'buttons': false
      });
    });

    $('input#search_sub').bind('click', function (e) {
        e.preventDefault();
        if (isKey())
            document.getElementById("search").submit();        else {
            document.getElementById('search').focus();
        }
    });
});
function show_book_down(obj) {
    var txt = '全本';

    if (trim(obj.chapterName).length > 2)
    {
        txt = obj.chapterName+'<font color=red>非全本</font>'
    }
    var str = '<div class=\"download-page\">' +
    '<h1><i>' + obj.bookName + '</i>' + txt + 'txt电子书免费下载</h1>' +
    '<div class=\"qr left\">'+
       ' <img src=\"/plug/QR.ashx?e=M&q=Zero&s=6&t='+obj.bookDownUrl+'\" />' +
       ' <p>本书二维码</p>'+
    '</div>'+
    '<div class=\"qr right\">'+
       ' <img src=\"/plug/QR.ashx?e=M&q=Zero&s=6&t=http://www.xiaoshuofang.com/download.aspx?action=reader\" />' +
        '<p>阅读器客户端二维码</p>'+
   ' </div>'+
    '<div class=\"book-btn\">'+
       ' <a class=\"abtn btn2 af\" href=\"' + obj.bookDownUrl + '\">点击下载</a>' +
       ' <a class=\"abtn btn3 ar\" href=\"\">阅读器下载</a>'+
   ' </div>' +
  ' <div class=\"download_ads\"><img src=\"/plug/QR.ashx?e=M&q=Zero&s=6&t=http://www.xiaoshuofang.com\"></div>' +
'</div>';
    $.Zebra_Dialog(str, {
        width:530,
        'type': false,
        'buttons': false
    });
}

function trim(str) {
    if (str!=null) 
        return str.replace(/ /g, "");
    else
        return '';
}



/* 获取url参数*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}




function InitAjax() //初始化浏览器类型
{
    var ajax = false;
    try {
        ajax = new ActiveXObject("Msxm12.XMLHTTP");
    } catch (e) {
        try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            ajax = false;
        }
    }
    if (!ajax && typeof XMLHttpRequest != 'undefined') {
        ajax = new XMLHttpRequest();
    }
    return ajax;
}
function ajax_login(name, passwd, resurl, cbSave) {
    var ajax = InitAjax();
    var urlRedirect = "/plug/login.ashx"; //后台处理页
    var poststring = "name=" + name + "&passwd=" + passwd + "&resurl=" + resurl + "&cbSave=" + cbSave;
    ajax.open("POST", urlRedirect, true);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(poststring);

    ajax.onreadystatechange = function () {
        if (ajax.readyState == 4 && ajax.status == 200) {
            var getMsg = ajax.responseText;
            if (trim(getMsg) == 1) {
                console.info([getMsg], null);
                $.Zebra_Dialog('登陆成功', {
                    'buttons': false,
                    'type': false, width: 300,
                    'modal': false,
                    'auto_close': 2000
                });
                window.location.replace(window.location.href);
            } else {
                $.Zebra_Dialog('用户名或密码错误', {
                    'type':false,
                    'buttons': false,
                    'modal': false,
                     width:300,
                    'auto_close': 2000
                });
            }
        }
    };
}


function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1
            c_end = document.cookie.indexOf(";", c_start)
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}

function isKey() {
    var key = document.getElementById('key').value;
    if (trim(key).length > 1 && trim(key).length < 10) {
        document.getElementById('key').style.boxShadow = '0 0 0 2px #00aec7';
        return true;
    } else {
        document.getElementById('key').style.boxShadow = '0 0 0 2px red';
        return false;
    }
}
